package com.example.demo.factory.version2_多态;


import java.util.Scanner;

/**
 * @author keyer
 * @Description : 描述
 * Created by cyd on 2021-05-24 14:04:20
 */
public class Calculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入数字A");
        double numberA = scanner.nextDouble();
        System.out.println("请输入数字B");
        double numberB = scanner.nextDouble();
        System.out.println("请输入操作符");
        String operate = scanner.next();


        double result = 0d;

        switch (operate) {
            case "+":
                Operation operationAdd = new OperationAdd();
                operationAdd.setNumberA(numberA);
                operationAdd.setNumberB(numberB);
                result = operationAdd.getResult();
                break;

            case "-":
                Operation operationSub = new OperationSub();
                operationSub.setNumberA(numberA);
                operationSub.setNumberB(numberB);
                result = operationSub.getResult();
                break;
            default:
                throw new IllegalStateException("不支持: " + operate);
        }

        System.out.println("结果为:" + result);
    }
}
